import pygame, sys, math
pygame.init()

from Ball import Ball
from PlayerBall import PlayerBall

clock = pygame.time.Clock()

width = 1280
height = 680
size = width, height

screen = pygame.display.set_mode(size)

background = pygame.image.load("background.png")
backgroundRect = background.get_rect()

bgColor = r,g,b = 0,0,0

ball1 = Ball(["ball.png"], [10,10], 1, [100,100], [100,100])
ball2 = Ball(["ball.png"], [6,5], 9, [75,75], [200,200])
ball3 = Ball(["ball.png"], [12,9], .5, [125,125], [400,100])
ball4 = Ball(["ball.png"], [4,4], 27, [300,300], [900,200])
ball5 = Ball(["ball.png"], [20,20], 10, [20,20], [500,400])
ballp = PlayerBall(["playerBall.png"] ,[4,4], [50,50], [250,100])

while True:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            sys.exit()
        if event.type == pygame.KEYDOWN:
            if event.key == pygame.K_d or event.key == pygame.K_RIGHT:
                ballp.direction("right")
            if event.key == pygame.K_a or event.key == pygame.K_LEFT:
                ballp.direction("left")
            if event.key == pygame.K_w or event.key == pygame.K_UP:
                ballp.direction("up")
            if event.key == pygame.K_s or event.key == pygame.K_DOWN:
                ballp.direction("down")
        if event.type == pygame.KEYUP:
            if event.key == pygame.K_d or event.key == pygame.K_RIGHT:
                ballp.direction("stop right")
            if event.key == pygame.K_a or event.key == pygame.K_LEFT:
                ballp.direction("stop left")
            if event.key == pygame.K_w or event.key == pygame.K_UP:
                ballp.direction("stop up")
            if event.key == pygame.K_s or event.key == pygame.K_DOWN:
                ballp.direction("stop down")
    
    ball1.update()
    ball2.update()
    ball3.update()
    ball4.update()
    ball5.update()
    ballp.update()
    
    ball1.collideWall(width, height)
    ball2.collideWall(width, height)
    ball3.collideWall(width, height)
    ball4.collideWall(width, height)
    ball5.collideWall(width, height)
    ballp.collideWall(width, height)
    
    ball1.collideBall(ball2)
    ball1.collideBall(ball3)
    ball2.collideBall(ball3)
    ball2.collideBall(ball4)
    ball1.collideBall(ball4)
    ball3.collideBall(ball4)
    ball5.collideBall(ball1)
    ball5.collideBall(ball2)
    ball5.collideBall(ball3)
    ball5.collideBall(ball4)
    ball5.collideBall(ball5)
    
    ballp.collideBall(ball1)
    ballp.collideBall(ball2)
    ballp.collideBall(ball3)
    ballp.collideBall(ball4)
    ballp.collideBall(ball5)
    
    #ball4.rot_center(ball4.image, 180)
    
    screen.fill(bgColor)
    screen.blit(background, backgroundRect)
    screen.blit(ball1.image, ball1.rect)
    screen.blit(ball2.image, ball2.rect)
    screen.blit(ball3.image, ball3.rect)
    screen.blit(ball4.image, ball4.rect)
    screen.blit(ball5.image, ball5.rect)
    screen.blit(ballp.image, ballp.rect)
    pygame.display.flip()
    clock.tick(60)